package cn.itsource.pet.controller;


import cn.itsource.basic.domain.AjaxResult;
import cn.itsource.basic.util.GetUserInfoUtil;
import cn.itsource.basic.util.PageList;
import cn.itsource.basic.util.RedisService;
import cn.itsource.pet.domain.SearchMasterMsg;
import cn.itsource.pet.domain.SearchMasterMsgQuery;
import cn.itsource.pet.service.SearchMasterMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/searchmaster")
public class SearchMasterMsgController {
    @Autowired
    RedisService redisService;
    @Autowired
    SearchMasterMsgService service;

    /**
     * 发布寻主
     * @param message
     * @param request
     * @return
     */
    @PostMapping("/publish")
    public AjaxResult publish(@RequestBody SearchMasterMsg message, HttpServletRequest request){
        Long userId = GetUserInfoUtil.getUserId();
        message.setUserId(userId);
        service.insert(message);

        return AjaxResult.me();
    }
    /**
     * /searchmaster/pagelist
     * 这里是寻主审核的分页查询
     */
    @PostMapping("/pagelist")
    public AjaxResult pagelist(@RequestBody SearchMasterMsgQuery query, HttpServletRequest request){
        Long userId = GetUserInfoUtil.getUserId();

        PageList<SearchMasterMsg> messages = service.pagelist(query);

        return AjaxResult.setResult(messages);
    }

    @PostMapping("shenghe")
    public AjaxResult shenghe(@RequestBody SearchMasterMsg message){
        return service.shenghe(message);
    }
}
